package com.ruoyi.ade.controller;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ade.domain.Standard;
import com.ruoyi.ade.service.IStandardService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 标准数据集Controller
 * 
 * @author wxh
 * @date 2025-06-02
 */
@RestController
@RequestMapping("/ade/standard")
public class StandardController extends BaseController
{
    @Autowired
    private IStandardService standardService;

    @PutMapping("/format")
    public AjaxResult format(){
        boolean r = standardService.fromat();
        if(r) return AjaxResult.success();
        return AjaxResult.error("Formatting is goning on..");
    }

    @PutMapping("/compare")
    public AjaxResult startCompare(){
        boolean r = standardService.startCompare();
        if(r) return AjaxResult.success();
        else return AjaxResult.error("Comparing is goning on..");
    }

    /**
     * 查询标准数据集列表
     */
    @PreAuthorize("@ss.hasPermi('ade:standard:list')")
    @GetMapping("/list")
    public TableDataInfo list(Standard standard)
    {
        startPage();
        List<Standard> list = standardService.selectStandardList(standard);
        return getDataTable(list);
    }

    /**
     * 查询标准数据集列表
     */
    @PreAuthorize("@ss.hasPermi('ade:standard:list')")
    @GetMapping("/wronglist")
    public TableDataInfo listWrong(Standard standard)
    {
        startPage();
        List<Standard> list = standardService.selectWrongStandardList(standard);
        return getDataTable(list);
    }

    /**
     * 导出标准数据集列表
     */
    @PreAuthorize("@ss.hasPermi('ade:standard:export')")
    @Log(title = "标准数据集", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Standard standard)
    {
        List<Standard> list = standardService.selectStandardList(standard);
        ExcelUtil<Standard> util = new ExcelUtil<Standard>(Standard.class);
        util.exportExcel(response, list, "标准数据集数据");
    }

    /**
     * 随机获取一条满足条件的数据
     * @param standard
     * @return
     */
    @PostMapping(value = "/random")
    public AjaxResult random(@RequestBody Standard standard){
        return AjaxResult.success(standardService.selectOneRandomStandard(standard));
    }

    /**
     * 获取标准数据集详细信息
     */
    @PreAuthorize("@ss.hasPermi('ade:standard:query')")
    @GetMapping(value = "/{id}")
    @Anonymous
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(standardService.selectStandardById(id));
    }

    /**
     * 新增标准数据集
     */
    @PreAuthorize("@ss.hasPermi('ade:standard:add')")
    @Log(title = "标准数据集", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Standard standard)
    {
        standard.setCreateBy(getUsername());
        return toAjax(standardService.insertStandard(standard));

    }


    /**
     * 修改标准数据集
     */
    @PreAuthorize("@ss.hasPermi('ade:standard:edit')")
    @Log(title = "标准数据集", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Standard standard)
    {
        standard.setUpdateBy(getUsername());
        return toAjax(standardService.updateStandard(standard));
    }


    /**
     * 删除标准数据集
     */
    @PreAuthorize("@ss.hasPermi('ade:standard:remove')")
    @Log(title = "标准数据集", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(standardService.deleteStandardByIds(ids));
    }
}
